import { View } from "../../../mvc/core/View";
import { ObjCreate } from "../common/ObjCreate";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { Alert } from "../../../../com/mui/controls/Alert";
import { PulseSharedObject } from "../player/PulseSharedObject";
import { GImageBitmap } from "../../../../com/mui/controls/GImageBitmap";
import { ImagesConst } from "../../resource/ImagesConst";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { Language } from "../../../../extend/language/Language";
import { BaseProgressBar } from "../common/BaseProgressBar";
import { ObjectPool } from "../../../../com/gengine/utils/pools/ObjectPool";
import { FlyFootBmp } from "../mapUI/flyFoot/FlyFootBmp";
import { FashionBoxFlyTargetBtn } from "./fashionFlyWing/FashionBoxFlyTargetBtn";
import { TigerMachine } from "./fashionFlyWing/tigerMachine/TigerMachine";
import { FashionBoxFlyWingAttTotalSp } from "./fashionFlyWing/FashionBoxFlyWingAttTotalSp";
import { FashionBoxFlyWingAttributWithValueSP } from "./fashionFlyWing/FashionBoxFlyWingAttributWithValueSP";
import { ResouceConst } from "../../../component/gconst/ResouceConst";
import { GameConst } from "../../../component/gconst/GameConst";
import { WuXingQualityBuyPanel } from "../wuxing/WuXingQualityBuyPanel";
import { ECategory } from "../../../../Message/Public/ECategory";
import { EProp } from "../../../../Message/Public/EProp";
import { ShopRule } from "../../rules/ShopRule";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { AIManager } from "../../scene/ai/AIManager";
import { Cache } from "../../cache/Cache";
import { ENpcEffect } from "../../../../Message/Public/ENpcEffect";
import { AIType } from "../../scene/ai/AIType";
import { CheckBoxWin } from "../common/alertwins/CheckBoxWin";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { WardrobeConfig } from "../../resource/WardrobeConfig";
import { MsgManager } from "../../manager/MsgManager";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { FashionBoxUtil } from "./FashionBoxUtil";
import { ToolTipInfo } from "../../model/ToolTipInfo";
import { NormalTooltip } from "../common/tooltip/NormalTooltip";
import { FashionBoxFlyWingTargetTips } from "./fashionFlyWing/FashionBoxFlyWingTargetTips";
import { Global } from "../../../../com/gengine/global/Global";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { AttriAddEffect } from "../effect/AttriAddEffect";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { GButton } from "../../../../com/mui/controls/GButton";
import { GCheckBox } from "../../../../com/mui/controls/GCheckBox";
type int = number;
//class FashionBoxFlyWingPanel
    
    export  class FashionBoxFlyWingPanel extends View
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        /* internal  */sortText(arg1: Array<any>, arg2: Object /* flash.display.DisplayObjectContainer */): void
        {
            var loc1=null;
            var loc4=0;
            var loc5=0;
            this.cleanAllSp();
            arg1.sortOn("key");
            var loc2=arg1.length;
            var loc3=Math.ceil(loc2 / 2);
            var loc6=0;
            while (loc6 < loc2) 
            {
                loc4 = Math.floor(loc6 % loc3) * 19;
                loc1 = ObjCreate.createTextField("", Math.floor(loc6 / loc3) * 118, loc4, 70, loc5, arg2);
                loc1.htmlText = HTMLUtil.addColor(arg1[loc6].name + "：", GlobalStyle.color1) + HTMLUtil.addColor(arg1[loc6].value, GlobalStyle.color2);
                ++loc6;
            }
            return;
        }

        /* internal  */onBtnClickHandlerI(arg1: int, arg2: Boolean): void
        {
            if (arg1 == Alert.OK) 
            {
                Alert.resetToDefault();
            }
            if (arg2) 
            {
                PulseSharedObject.save("FashionBoxFlyWingAutoBuy", true);
            }
            return;
        }

        /* internal  */init(): void
        {
            this._lvSp = new Object /* flash.display.Sprite */();
            this._lvSp.x = 0;
            this._lvSp.y = 0;
            addChild(this._lvSp);
            addChild(new GImageBitmap(ImagesConst.flywingLogoBg, 2, 106));
            this._attSp = new Object /* flash.display.Sprite */();
            this._attSp.x = 194;
            this._attSp.y = 106;
            addChild(this._attSp);
            ObjCreate.createBg(2, 2, 689, 102, this._lvSp);
            this._stCurFlyLvBm = ObjCreate.createBitmap("", 131, 25, this._lvSp);
            this._stAllAttBm = ObjCreate.createBitmap("", 444, 2, this._lvSp);
            this._curLvTx = ObjCreate.createGTextField("", 292, 17, 60, 28, this._lvSp, new GTextFormat(FontUtil.EmbedNumberName, 24, 6350622));
            this._addBtn = ObjCreate.createGButton(Language.getString(74656), 340, 23, 60, 22, this._lvSp, "ButtonRedMini");
            this._addBtn.toolTipData = HTMLUtil.addColor(Language.getString(74655), "#ffffff");
            this._addBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onAddBtnClickHandler);
            this._lvProgressBar = new BaseProgressBar(ImagesConst.BlessBarBg);
            this._lvProgressBar.mouseEnabled = false;
            this._lvProgressBar.setLabelPosition(0, 11);
            this._lvProgressBar.progressBarClass = ImagesConst.BlessBar;
            this._lvProgressBar.showProgressText = true;
            this._lvProgressBar.setSize(379, 35);
            this._lvProgressBar.setProgressPosition(18, 14);
            this._lvProgressBar.move(37, 48);
            this._lvSp.addChild(this._lvProgressBar);
            ObjCreate.createBg(563, 20, 90, 3, this._lvSp, ImagesConst.Line).rotation = 90;
            this._allAttSp = new Object /* flash.display.Sprite */();
            this._allAttSp.x = 467;
            this._allAttSp.y = 24;
            this._lvSp.addChild(this._allAttSp);
            this._debugResultTx = ObjCreate.createGTextField("", 1, 10, 190, 20, this._lvSp, GlobalStyle.textFormat2);
            ObjCreate.createGTextField(Language.getString(74403), 100, 81, 190, 20, this._lvSp, null, true);
            this._autoAITx = ObjCreate.createGTextField(Language.getString(74404), 186, 81, 190, 20, this._lvSp, null, true);
            this._autoAITx.addEventListener(flash.events.TextEvent.LINK, this.onTxClickHandler);
            this._flyFoot = ObjectPool.getObject(FlyFootBmp);
            this._flyFoot.x = 298;
            this._flyFoot.y = 83;
            this._lvSp.addChild(this._flyFoot);
            this._flyFoot.addEventListener(flash.events.MouseEvent.CLICK, this.onFlyTransport);
            ObjCreate.createBg(0, 0, 496, 305, this._attSp);
            ObjCreate.createBg(0, 0, 480, 24, this._attSp, ImagesConst.TileBg);
            this._stFlyGrowBm = ObjCreate.createBitmap("", 180, 5, this._attSp);
            this._targetBtn = new FashionBoxFlyTargetBtn();
            this._targetBtn.x = 445;
            this._targetBtn.y = -3;
            this._attSp.addChild(this._targetBtn);
            this._tiger = new TigerMachine();
            this._tiger.x = 8;
            this._tiger.y = 28;
            this._attSp.addChild(this._tiger);
            this._growBtn = ObjCreate.createGButton(Language.getString(74660), 402, 42, 70, 28, this._attSp, "ButtonRedMini");
            this._growBatchBtn = ObjCreate.createGButton(Language.getString(74661), 402, 77, 70, 28, this._attSp, "ButtonRedMini");
            this._growBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onGrowBtnClick);
            this._growBatchBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onGrowBtnClick);
            this._attTotalPart = new FashionBoxFlyWingAttTotalSp();
            this._attTotalPart.x = 22;
            this._attTotalPart.y = 136;
            this._attSp.addChild(this._attTotalPart);
            this._attSp.addChild(new GImageBitmap(ImagesConst.wxGradeArrow, 315, 156));
            ObjCreate.createGTextField(Language.getString(74665), 374, 116, 120, 20, this._attSp, GlobalStyle.textFormat2);
            this._attAddPart = new FashionBoxFlyWingAttributWithValueSP();
            this._attAddPart.x = 368;
            this._attAddPart.y = 136;
            this._attSp.addChild(this._attAddPart);
            var loc1=ResouceConst.getScaleBitmap(ImagesConst.DisabledBg);
            loc1.x = 6;
            loc1.y = 255;
            loc1.setSize(485, 54);
            this._attSp.addChild(loc1);
            this._tongQianTx = ObjCreate.createTextField(GameConst.cultureFlyGrowCoinBindPer.toString(), 348, 262, 50, 20, this._attSp, GlobalStyle.textFormat2);
            this._tongQianTx.autoSize = flash.text.TextFormatAlign.RIGHT;
            ObjCreate.createBitmap(ImagesConst.Tongqian, 400, 262, this._attSp);
            ObjCreate.createGTextField(Language.getString(26341) + "：", 21, 258, 80, 20, this._attSp);
            ObjCreate.createGTextField(Language.getString(44460) + "：", 304, 262, 80, 20, this._attSp);
            this._buyPanel = new WuXingQualityBuyPanel(ECategory._ECategoryProp, EProp._EPropFlyGrow, false, false, false, ShopRule.ShopMallProp);
            this._buyPanel.x = 80;
            this._buyPanel.y = 243;
            this._attSp.addChild(this._buyPanel);
            this._buyPanel.updateNeedCount(GameConst.cultureFlyGrowPropNumPer);
            this._desTx = ObjCreate.createGTextField("", 69, 387, 66, 20, this, GlobalStyle.textFormat5);
            this._desTx.htmlText = Language.getString(71127);
            this._desTx.toolTipData = Language.getString(74652);
            this._autoBuy = ObjCreate.createCheckBox(Language.getString(26338), 304, 283, 140, 22, this._attSp);
            this._autoBuy.textField.filters = [FilterConst.nameGlowFilter];
            this._autoBuy.addEventListener(flash.events.Event.CHANGE, this.onAutoBuyChangeHandler);
            LoaderHelp.addResCallBack(ResFileConst.fashionFlyWing, this.onLoadBmResource);
            return;
        }

        protected onTxClickHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            AIManager.onAutoPathAIControl(Cache.instance.scene.getNpcByEffect(ENpcEffect._ENpcEffectMeritExchange));
            return;
        }

        /* internal  */onFlyTransport(arg1: Object /* flash.events.MouseEvent */): void
        {
            AIManager.onAIControl(Cache.instance.scene.getNpcByEffect(ENpcEffect._ENpcEffectMeritExchange), AIType.AI_Convey);
            return;
        }

        protected onAutoBuyChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=false;
            if (this._autoBuy.selected) 
            {
                loc1 = !PulseSharedObject.isTodayNotTips("FashionBoxFlyWingAutoBuy");
                if (loc1) 
                {
                    Alert.okLabel = Language.getString(69901);
                    Alert.buttonWidth = 60;
                    Alert.showCloseBtn = false;
                    Alert.alertWinRenderer = CheckBoxWin;
                    Alert.show(Language.getString(74663), null, Alert.OK, null, this.onBtnClickHandlerI);
                }
            }
            return;
        }

        protected onGrowBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (!this.lvLimit()) 
            {
                return;
            }
            if (!this.cangoGrow()) 
            {
                return;
            }
            var loc1=Cache.instance.pack.backPackCache.getUidListByType(ECategory._ECategoryProp, EProp._EPropFlyGrow);
            var loc2=arg1.target;
            switch (loc2) 
            {
                case this._growBtn:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.FashionFlyWingGoGrow, {"batch": false, "autoBuy": this._autoBuy.selected, "uids": loc1}));
                    this.controlGrowBtnEnable(false);
                    break;
                }
                case this._growBatchBtn:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.FashionFlyWingGoGrow, {"batch": true, "autoBuy": this._autoBuy.selected, "uids": loc1}));
                    this.controlGrowBtnEnable(false);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }

        /* internal  */lvLimit(): Boolean
        {
            var loc1=0;
            var loc2=0;
            var loc3=0;
            var loc4=0;
            var loc5=0;
            while (loc5 < 5) 
            {
                loc2 = Cache.instance.wardrobe.FlyWingAttArr[loc5];
                loc1 = Cache.instance.wardrobe.flyWingInfo.growLevelMap[loc2];
                loc3 = WardrobeConfig.instance.getFlyGrowLvLimit(Cache.instance.wardrobe.flyWingInfo.flyLevel);
                if (loc1 >= loc3) 
                {
                    ++loc4;
                }
                ++loc5;
            }
            if (loc4 == 5) 
            {
                MsgManager.showRollTipsMsg(Language.getString(74664));
                return false;
            }
            return true;
        }

        public startTiger(): void
        {
            this._tiger.start(Cache.instance.wardrobe.flyWingTigerResultArr);
            return;
        }

        public showResult(): void
        {
            this._tiger.showResult(Cache.instance.wardrobe.flyWingTigerResultArr);
            return;
        }

        public controlGrowBtnEnable(arg1: Boolean): void
        {
            if (arg1) 
            {
                this._growBtn.mouseEnabled = true;
                this._growBatchBtn.mouseEnabled = true;
                this._growBtn.filters = [];
                this._growBatchBtn.filters = [];
            }
            else 
            {
                this._growBtn.mouseEnabled = false;
                this._growBatchBtn.mouseEnabled = false;
                this._growBtn.filters = [FilterConst.colorFilter];
                this._growBatchBtn.filters = [FilterConst.colorFilter];
            }
            return;
        }

        /* internal  */cangoGrow(): Boolean
        {
            var loc1=Cache.instance.role.money.coinBind + Cache.instance.role.money.coin;
            if (loc1 < GameConst.cultureFlyGrowCoinBindPer) 
            {
                MsgManager.showRollTipsMsg(Language.getString(70060));
                Dispatcher.dispatchEvent(new DataEvent(EventName.ShopMallAutoBuyCoin, GameConst.cultureFlyGrowCoinBindPer - loc1));
                return false;
            }
            var loc2=Cache.instance.pack.backPackCache.getItemCountByCategoryAndType(ECategory._ECategoryProp, EProp._EPropFlyGrow);
            if (this._autoBuy.selected) 
            {
                if (this._buyPanel.yuanbaoPrice > Cache.instance.role.money.gold && loc2 < GameConst.cultureFlyGrowPropNumPer) 
                {
                    if (this._buyPanel.yuanbaoPrice > Cache.instance.role.money.gold) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(41005) + "!");
                        return false;
                    }
                    if (loc2 < GameConst.cultureFlyGrowPropNumPer) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(71109));
                        return false;
                    }
                }
            }
            else if (loc2 < GameConst.cultureFlyGrowPropNumPer) 
            {
                MsgManager.showRollTipsMsg(Language.getString(71109));
                return false;
            }
            return true;
        }

        /* internal  */onLoadBmResource(): void
        {
            this._stCurFlyLvBm.bitmapData = GlobalClass.getBitmapData(ImagesConst.FBcurFlyWingLv);
            this._stFlyGrowBm.bitmapData = GlobalClass.getBitmapData(ImagesConst.FBFlyGrow);
            this._stAllAttBm.bitmapData = GlobalClass.getBitmapData(ImagesConst.FBALLAtt);
            return;
        }

        protected onAcceptBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            return;
        }

        protected onAddBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (Cache.instance.wardrobe.flyWingInfo.flyLevel >= WardrobeConfig.instance.getMaxFlyLv()) 
            {
                MsgManager.showRollTipsMsg(Language.getString(60374));
                return;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.FashionFlyWingUpgradeLvViewOpen));
            return;
        }

        public updateInfo(): void
        {
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc6=0;
            var loc7=null;
            var loc8=0;
            this._curLvTx.text = Cache.instance.wardrobe.flyWingInfo.flyLevel.toString();
            this._lvProgressBar.setValue(Cache.instance.wardrobe.flyWingInfo.flyExp, WardrobeConfig.instance.getFlyLvNeddExp(Cache.instance.wardrobe.flyWingInfo.flyLevel));
            var loc1=FashionBoxUtil.getArrFromDic(Cache.instance.wardrobe.flyWingInfo.growLevelMap, Cache.instance.wardrobe.FlyWingAttArr);
            this._targetBtn.toolTipData = new ToolTipInfo(NormalTooltip.ToolTipRenderType_Sprite, loc1, new FashionBoxFlyWingTargetTips());
            var loc2=Cache.instance.wardrobe.getAllFlyWingAtt();
            this.sortText(loc2, this._allAttSp);
            this._attTotalPart.updateInfo(Cache.instance.wardrobe.flyWingInfo.growLevelMap, Cache.instance.wardrobe.flyWingInfo.growValueMap);
            this._attAddPart.updateInfo(Cache.instance.wardrobe.addGrowValueMap);
            if (Global.isDebugModle) 
            {
                loc3 = "";
                loc4 = Cache.instance.wardrobe.flyWingTigerResultArr;
                loc7 = "";
                loc8 = 0;
                while (loc8 < loc4.length) 
                {
                    loc6 = loc4[loc8];
                    if (loc5 = GameDefConfig.instance.getEJewel(loc6)) 
                    {
                        if (loc6 == 12 || loc6 == 13) 
                        {
                            loc7 = Language.getString(36306);
                        }
                        else if (loc6 == 8 || loc6 == 9) 
                        {
                            loc7 = Language.getString(36305);
                        }
                        else 
                        {
                            loc7 = loc5.text1;
                        }
                    }
                    loc3 = loc3 + (loc7 + ",");
                    ++loc8;
                }
                this._debugResultTx.text = loc3;
            }
            else 
            {
                this._debugResultTx.text = "";
            }
            return;
        }

        public updateProp(): void
        {
            this._buyPanel.updatePackData();
            return;
        }

        public cleanAllSp(): void
        {
            while (this._allAttSp.numChildren > 0) 
            {
                this._allAttSp.removeChildAt(0);
            }
            return;
        }

        public updateFlyWingLv(arg1: int): void
        {
            this.addGrowthEffect(arg1);
            return;
        }

        /* internal  */addGrowthEffect(arg1: int, arg2: Boolean=false): void
        {
            var loc1=new Object /* flash.geom.Point */(Global.stage.mouseX, Global.stage.mouseY);
            var loc2=localToGlobal(new Object /* flash.geom.Point */(180, 80));
            AttriAddEffect.attriAdd(arg1, loc2.x, loc2.y, arg2);
            return;
        }

        public shineResult(arg1: Boolean): void
        {
            this._tiger.shineResult(arg1);
            return;
        }

        public shineBar(arg1: Map<any, any> /* flash.utils.Dictionary */): void
        {
            this._attTotalPart.shineBar(arg1);
            return;
        }

        /* internal */ /* var */_lvSp: Object /* flash.display.Sprite */;

        /* internal */ /* var */_attSp: Object /* flash.display.Sprite */;

        /* internal */ /* var */_stCurFlyLvBm: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_stFlyGrowBm: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_flyFoot: FlyFootBmp;

        /* internal */ /* var */_targetBtn: FashionBoxFlyTargetBtn;

        /* internal */ /* var */_desTx: GTextFiled;

        /* internal */ /* var */_curLvTx: Object /* flash.text.TextField */;

        /* internal */ /* var */_addBtn: GButton;

        /* internal */ /* var */_lvProgressBar: BaseProgressBar;

        /* internal */ /* var */_allAttSp: Object /* flash.display.Sprite */;

        /* internal */ /* var */_autoAITx: Object /* flash.text.TextField */;

        /* internal */ /* var */_tiger: TigerMachine;

        /* internal */ /* var */_growBtn: GButton;

        /* internal */ /* var */_growBatchBtn: GButton;

        /* internal */ /* var */_attTotalPart: FashionBoxFlyWingAttTotalSp;

        /* internal */ /* var */_attAddPart: FashionBoxFlyWingAttributWithValueSP;

        /* internal */ /* var */_tongQianTx: Object /* flash.text.TextField */;

        /* internal */ /* var */_autoBuy: GCheckBox;

        /* internal */ /* var */_buyPanel: WuXingQualityBuyPanel;

        /* internal */ /* var */_debugResultTx: Object /* flash.text.TextField */;

        /* internal */ /* var */_stAllAttBm: Object /* flash.display.Bitmap */;
    }
